package work.linruchang.oauthclientproject.controller;

import cn.hutool.core.util.StrUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import work.linruchang.oauthclientproject.util.EnhanceSpringUtil;

import javax.servlet.http.HttpServletRequest;

/**
 * 首页
 *
 * @author LinRuChang
 * @version 1.0
 * @date 2022/08/30
 * @since 1.8
 **/
@Controller
public class IndexController {

    @GetMapping(value= {"", "index"})
    public String indexPage(Model model) {
        HttpServletRequest currrentRequest = EnhanceSpringUtil.getCurrrentRequest();
        String serverName = currrentRequest.getServerName();
        Integer port = currrentRequest.getServerPort();
        String contextPath = currrentRequest.getContextPath();



        model.addAttribute("oauthLoginUrl", StrUtil.format("http://{}:{}{}/user-oauth/login",serverName,port,contextPath));
        model.addAttribute("oauthInfoAdminUrl", StrUtil.format("http://{}:{}{}/user-oauth/oauth-info-admin",serverName,port,contextPath));

        return "index";
    }

}
